package com.shop2cn.iapi.agentproducts.service;

import java.util.List;

import com.google.common.reflect.TypeToken;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.shop2cn.iapi.agentproducts.parameter.ProductListDto;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.EnvSetup;
/**
*查询商品列表Call
*FreeMaker Template自动生成代码
*/
public class QueryProductListCallV2 extends YmatouBaseCall{
	private static String opurl ="product/queryProductList";
	
	public QueryProductListCallV2() {
		super(EnvSetup.getSystemUrl("agentproducts_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	
	public List<ProductListDto> getProductList(){
		JsonElement productList = getJsonObject().get("data").getAsJsonObject().get("productList");
		String sResults=productList.isJsonNull()?new JsonArray().toString():productList.getAsJsonArray().toString();
		List<ProductListDto> FreezeProductResultList=(List<ProductListDto>) FormatUtil.GSONToObject(sResults, new TypeToken<List<ProductListDto>>(){}.getType());
		return FreezeProductResultList;
	}
	
}